/*
 * @Author       : wangzeyu 2309335887@qq.com
 * @Date         : 2023-06-29 14:47:18
 * @LastEditors  : WangZeYu
 * @LastEditTime : 2023-06-29 16:14:14
 * @FilePath     : \algorithm\quickSort.js
 * @Description  : 快速排序
 */
function quickSort(arr) {
  if (arr.length <= 1) {
    return arr
  }
  let base = arr[0]
  let minArr = arr.slice(1).filter(item => item <= base)
  let maxArr = arr.slice(1).filter(item => item > base)
  console.log('较小数组:', minArr, '基准值:', base, '较大数组:', maxArr)
  return quickSort(minArr).concat(base).concat(quickSort(maxArr))
}

let a = [3, 5, 4, 2, 1, 15]

console.log(quickSort(a))